using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using com.hp.hpl.jena.ontology;
using com.hp.hpl.jena.rdf.model;
using System.Collections;
using com.hp.hpl.jena.util.iterator;

namespace Test1
{
    public class JEnumerator<T> :IEnumerable<T>
    {
        private ExtendedIterator iter;
        public JEnumerator(ExtendedIterator iter)
        {
            this.iter = iter;
        }

        #region IEnumerable<T> Members

        ///<summary>
        ///Returns an enumerator that iterates through the collection.
        ///</summary>
        ///
        ///<returns>
        ///A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
        ///</returns>
        ///<filterpriority>1</filterpriority>
        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            while(iter.hasNext())
                yield return (T) iter.next();
        }

        #endregion

        #region IEnumerable Members

        ///<summary>
        ///Returns an enumerator that iterates through a collection.
        ///</summary>
        ///
        ///<returns>
        ///An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
        ///</returns>
        ///<filterpriority>2</filterpriority>
        public IEnumerator GetEnumerator()
        {
            while(iter.hasNext())
                yield return iter.next();
        }

        #endregion
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string ns = "file:/c/Users/andrew.matthews/Documents/MyOntologies/2007/02/Test/test.n3#";
            string urlbase = "file:///C:/Users/andrew.matthews/Documents/MyOntologies/2007/02/Test/";
            OntDocumentManager mgr = new OntDocumentManager();
            // set the mgr's properties now
            // now use it
            OntModelSpec s = new OntModelSpec(OntModelSpec.RDFS_MEM);
            s.setDocumentManager(mgr);
            OntModel m = ModelFactory.createOntologyModel(s);
            Model model = m.read(urlbase + "needs.owl");
            for(NsIterator nsit = model.listNameSpaces();nsit.hasNext();)
            {
                Debug.WriteLine("Namespace: "+nsit.nextNs());
            }
            for(NodeIterator nit = model.listObjects();nit.hasNext();)
            {
                RDFNode node = nit.nextNode();
                Debug.WriteLine("Node: "+node.toString());
            }

            m.addSubModel(model);

            Debug.WriteLine("There are " + m.countSubModels() + " submodels");

            OntClass Need = m.getOntClass(ns + "Need");
            Debug.WriteLine("Need: " + Need.toString());
        }
    }
}